package com.cenjiawen.common;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Set;

import com.cjw.model.DBMap;
import com.jfinal.kit.JsonKit;
import com.utils.gen.GenUtils;

import cn.hutool.core.io.file.FileReader;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

public class GenTest {

	public static void main(String[] args) throws SQLException {

		// Hashids HASHID = new Hashids("zhenyuding", 38);
		// System.out.println(HASHID.encode(2));
		// System.out.println(RandomUtil.randomString(32));
		// GenUtils.gen();
		// GenUtils.gen("test.zhen-yee.com", "dati", "root", "Cendb", "dati");
		// // GenUtils.gen("test.zhen-yee.com", "dati", "root", "zhenyi",
		// "dati");
		GenUtils.gen("yitai.zhen-yee.com", "cms", "root", "yitaikeji", "yitaicms");
		// GenUtils.gen("app.superlink.mobi", "liuxue", "dev", "dev", "liuxue");
		// GenUtils.gen("192.168.50.222", "jiahua", "root", "zhenyi", "jiahua");
		// GenUtils.gen("192.168.199.213", "xhc", "root", "Cendb", "xhc");
		// GenUtils.gen("192.168.50.222", "xhc", "root", "zhenyi", "xhc");
		// GenUtils.gen("dev.zhen-yee.com", "youqu", "root", "Cendb", "youqu");
		// GenUtils.gen("localhost", "youqu", "root", "Cendb", "youqu");
		// GenUtils.gen("192.168.50.222", "youqu", "root", "zhenyi", "youqu");
		// GenUtils.gen("192.168.50.222", "zhaozheng", "root", "zhenyi",
		// "zhaozheng");
		// GenUtils.gen("dev.zhen-yee.com", "pxlm", "root", "Cendb", "pxlm");
		// new GenTest().b();
		// String
		// HTMLText="'[{\"address\":null,\"addTime\":null,\"intro\":null,\"name\":\"华发校区\",\"id\":2}]";
		// System.out.println(StringEscapeUtils.escapeHtml(HTMLText));
		// System.out.println(StringEscapeUtils.escapeJavaScript(HTMLText));

		// DruidDataSource ds2 = new DruidDataSource();
		// ds2.setUrl("jdbc:mysql://123.56.145.42:3306/superlink");
		// ds2.setUsername("dev");
		// ds2.setPassword("dev");
		//
		// String imgHost = "http://res.superlinkplus.com/";
		// SqlRunner runner = SqlRunner.create(ds2);
		//
		// Long certId = 91309L;
		// List<Entity> list =
		// runner.findAll(Entity.create("super_course").set("certificate_id",
		// certId));
		// for (Entity course : list) {
		// Long courseId = course.getLong("id");
		// String courseTitle = course.getStr("name");
		// Integer courseSort = course.getInt("sort");
		// Integer courseStatus = course.getInt("status");
		// String content = course.getStr("content");
		//
		// String[] images = content.split(",");
		//
		// String newContent = "";
		// for (String string : images) {
		// String url = imgHost + string;
		// newContent = newContent + url + ";";
		// }
		// String duration = course.getStr("long");
		// // content = content.replace(",", ";");
		// LxCertificateItem certificateItem = new LxCertificateItem();
		// certificateItem.setTitle(courseTitle);
		// certificateItem.setContent(newContent);
		// certificateItem.setDuration(duration);
		// certificateItem.setCertificateId(certId);
		// certificateItem.setSort(courseSort);
		// certificateItem.setStatus(courseStatus);
		// System.out.println(JsonKit.toJson(certificateItem));
		// }

		// Long courseId = 58L;
		// List<Entity> exams =
		// runner.findAll(Entity.create("super_exam").set("course_id",
		// courseId));
		// for (Entity exam : exams) {
		// String option = exam.getStr("option");
		// String answer = exam.getStr("answer");
		// String[] answers = answer.split(",");
		//
		// ArrayList<DBMap> list = new ArrayList<DBMap>();
		// String[] options = option.split("\r\n");
		// for (String string : options) {
		// String selectionName = string.split(":")[0];
		// String contents = string.split(":")[1];
		// boolean isAnswer = false;
		// for (String answerName : answers) {
		// if (answerName.equals(selectionName)) {
		// isAnswer = true;
		// }
		// }
		// DBMap map = new DBMap();
		// map.put("title", contents);
		// map.put("isAnswer", isAnswer ? 1 : 0);
		// list.add(map);
		// }
		// System.out.println(JsonKit.toJson(list));
		// }
	}

	public void b() {
		String json = new FileReader("/Users/cen/BeikangAyi/ROOT/jh/json/minzu.json").readString();
		JSONObject jsonObject = JSONUtil.parseObj(json);
		JSONArray array = jsonObject.getJSONArray("data");
		ArrayList<DBMap> arrayList = new ArrayList<>();
		for (int i = 0; i < array.size(); i++) {
			JSONObject object = array.getJSONObject(i);
			String name = object.getStr("name");
			DBMap mapD = new DBMap();
			Integer id = object.getInt("id");
			mapD.put("value", id);
			mapD.put("label", name);
			arrayList.add(mapD);
		}
		System.out.println(JsonKit.toJson(arrayList));
	}

	public void a() {
		String json = new FileReader("C:\\Users\\Administrator\\Desktop\\city.json").readString();
		// System.out.println(json);
		JSONObject jsonObject = JSONUtil.parseObj(json);
		ArrayList<DBMap> arrayList = new ArrayList<>();
		Set<String> provinceNames = jsonObject.keySet();
		for (String provinceName : provinceNames) {
			DBMap mapP = new DBMap();
			mapP.put("value", provinceName);
			mapP.put("label", provinceName);
			JSONObject obj = jsonObject.getJSONObject(provinceName);
			Set<String> cityKeys = obj.keySet();
			ArrayList<DBMap> provinceChildrens = new ArrayList<>();
			for (String cityName : cityKeys) {
				DBMap mapC = new DBMap();
				mapC.put("value", cityName);
				mapC.put("label", cityName);
				provinceChildrens.add(mapC);
				Set<String> disKeys = obj.keySet();
				ArrayList<DBMap> cityChildrens = new ArrayList<>();
				Object[] objDis = obj.getJSONArray(cityName).toArray();
				for (Object object : objDis) {
					DBMap mapD = new DBMap();
					mapD.put("value", String.valueOf(object));
					mapD.put("label", String.valueOf(object));
					cityChildrens.add(mapD);
				}
				mapC.put("children", cityChildrens);
			}
			mapP.put("children", provinceChildrens);
			arrayList.add(mapP);
		}
		System.out.println(JsonKit.toJson(arrayList));
	}
}
